﻿/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-11-3
Description:CQuery_ReportList.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Text;
using FineUI;
using FTchina.SearchQuery;
using FTchina.Library;
using FTchina;
using PWMIS.DataMap.Entity;
using FTchina.Models;
using System.Linq;
public partial class CQuery_ShowReportList_cs : BasePage
{



    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

            BindGrid();
        }
    }


    #region 绑定列表
    private void BindGrid()
    {
        BindGrid(false);
    }

    /// <summary>
    /// 绑定表格
    /// </summary>
    private void BindGrid(bool IsToExcel)
    {
        //每页条数
        Grid1.PageSize = 15;

        CQuery_ReportList mCQuery_ReportList = new CQuery_ReportList();
        Cquery_ReportPermission mCquery_ReportPermission = new Cquery_ReportPermission();

        OQL q_premissionlist = new OQL(mCquery_ReportPermission);
        OQLCompare cmpp = new OQLCompare(mCquery_ReportPermission);
        OQLCompare cmppresult = cmpp.Comparer(mCquery_ReportPermission.UID, OQLCompare.CompareType.Equal, MasterHelper.UID);
        q_premissionlist.Select(mCquery_ReportPermission.Guid).Where(cmppresult);
        q_premissionlist.Distinct = true;
        List<Cquery_ReportPermission> plist = EntityQuery<Cquery_ReportPermission>.QueryList(q_premissionlist, mCquery_ReportPermission);




        //拼接查询条件
        OQLCompare cmp = new OQLCompare(mCQuery_ReportList);
        OQLCompare cmpResult = (cmp.Comparer(mCQuery_ReportList.ReportName, OQLCompare.CompareType.Like, "%" + ttbSearch.Text.Trim() + "%"));
        OQL q = new OQL(mCQuery_ReportList);
        q.Select().Where(cmpResult);//按条件查询条件

        List< CQuery_ReportList> rlist=EntityQuery<CQuery_ReportList>.QueryList(q, mCQuery_ReportList);


        List< CQuery_ReportList> gridlist=new List<CQuery_ReportList>();


        foreach (CQuery_ReportList item in rlist)
        {
            foreach (Cquery_ReportPermission Pitem in plist)
            {
                if (Pitem.Guid == item.Guid)
                {
                    gridlist.Add(item);
                    continue;
                }
            }
        }

        int count = gridlist.Count;//获取分页前的条数

        if (IsToExcel)
        {//如果是导出Excel
            FTchina.OfficeHelper.ToExcel.IListToExcel(gridlist);
            return;
        }

        gridlist.Skip<CQuery_ReportList>(Grid1.PageIndex * Grid1.PageSize).Take<CQuery_ReportList>(Grid1.PageSize);
 
        Grid1.RecordCount = count;
        Grid1.DataSource = gridlist;
        Grid1.DataBind();





    }
    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Grid1_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
    {

        Grid1.PageIndex = e.NewPageIndex;
        BindGrid();
    }
    /// <summary>
    /// 删除按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        foreach (int row in Grid1.SelectedRowIndexArray)
        {
            sb.Append(Grid1.DataKeys[row][0].ToString());
            sb.Append(",");
        }
        foreach (string ids in sb.ToString().TrimEnd(',').Split(','))
        {

            FTchina.BLL.CQuery_ReportListManager.DeleteCQuery_ReportListById(Convert.ToInt32(ids));
        }
        BindGrid();
        Grid1.SelectedRowIndexArray = new int[] { };//去除默认的选项
    }


    /// <summary>
    /// 弹出窗口返回的处理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Window1_Close(object sender, EventArgs e)
    {
        BindGrid();
    }
    #endregion

    #region 搜索过滤
    /// <summary>
    /// 点击搜索上的关闭按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ttbSearch_Trigger1Click(object sender, EventArgs e)
    {
        ttbSearch.ShowTrigger1 = false;
        ttbSearch.Text = String.Empty;//清空搜索字符串
        BindGrid();
    }
    /// <summary>
    /// 点击搜索按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ttbSearch_Trigger2Click(object sender, EventArgs e)
    {
        ttbSearch.ShowTrigger1 = true;//显示关闭搜索按钮

        BindGrid();
    }


    #endregion


    #region 导出Excel
    /// <summary>
    /// 带过滤条件的导出，不分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcel_click(object sender, EventArgs e)
    {
        BindGrid(true);
    }
    #endregion


}






